#include "WEPrecompile.h"
#include "WEImage.h"

namespace iMate
{
	IMPLEMENT_CLASS(WEImage, wxWindow)
	BEGIN_EVENT_TABLE(WEImage, wxWindow)
		 EVT_PAINT(WEImage::OnPaint)
	END_EVENT_TABLE()

	
	WEImage::WEImage(wxWindow* parent,wxWindowID id,const wxSize &size,const wxString &fileName)
	: wxWindow(parent,id,wxDefaultPosition,size,wxNO_BORDER|wxFULL_REPAINT_ON_RESIZE)
	{
		mImage.Destroy();
		if (fileName != wxT(""))
			setImage(fileName);
	}
	WEImage::~WEImage()
	{

	}
	void WEImage::OnPaint(wxPaintEvent& WXUNUSED(event))
    {			
		wxPaintDC dc( this );
		dc.SetBackgroundMode(wxSOLID);
		if (mImage.Ok())
		{
			dc.Clear();
			wxBitmap bmp(mImage);
			if (bmp.Ok())
				dc.DrawBitmap( bmp, 0, 0);
		}
    }
	void WEImage::setImage(const wxString &fileName)
	{
		mImage.Destroy();
		mImage.LoadFile(fileName);
		if (mImage.Ok())
		{
			this->Refresh();
		}

	}
}